Public Function ConvertToDecimal(ByVal bits As String) As String
  ' Przeznaczenie:  konwersja liczby binarnej na dziesitn
  '
  ' Parametry:
  '  bits   acuch bitw stanowicych liczb binarn
  '
  ' Zwracana warto:
  '  string  dziesitna reprezentacja liczby binarnej
  '
  Dim i, Length As Integer ' zmienne pomocnicze
  Dim result As Long ' wynik

  Length = bits.Length - 1
  result = 0
  i = 0
  While Length >= 0
    If bits.SubString(i, 1) = "1" Then
      result += 2 ^ Length
    End If
    Length -= 1
    i += 1
  End While
  ConvertToDecimal = CStr(result)
End Function
